package com.ruoyi.wms.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.idempotent.annotation.RepeatSubmit;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.web.core.BaseController;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.wms.domain.vo.MailboxInstructionsVo;
import com.ruoyi.wms.domain.bo.MailboxInstructionsBo;
import com.ruoyi.wms.service.MailboxInstructionsService;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;

/**
 * 来信须知
 *
 * @author zcc
 * @date 2024-12-14
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wms/instructions")
public class MailboxInstructionsController extends BaseController {

    private final MailboxInstructionsService mailboxInstructionsService;

    /**
     * 查询来信须知列表
     */
    @SaCheckPermission("wms:instructions:list")
    @GetMapping("/list")
    public TableDataInfo<MailboxInstructionsVo> list(MailboxInstructionsBo bo, PageQuery pageQuery) {
        return mailboxInstructionsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出来信须知列表
     */
    @SaCheckPermission("wms:instructions:export")
    @Log(title = "来信须知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MailboxInstructionsBo bo, HttpServletResponse response) {
        List<MailboxInstructionsVo> list = mailboxInstructionsService.queryList(bo);
        ExcelUtil.exportExcel(list, "来信须知", MailboxInstructionsVo.class, response);
    }

    /**
     * 获取来信须知详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("wms:instructions:query")
    @GetMapping("/{id}")
    public R<MailboxInstructionsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(mailboxInstructionsService.queryById(id));
    }

    /**
     * 新增来信须知
     */
    @SaCheckPermission("wms:instructions:add")
    @Log(title = "来信须知", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MailboxInstructionsBo bo) {
        mailboxInstructionsService.insertByBo(bo);
        return R.ok();
    }

    /**
     * 修改来信须知
     */
    @SaCheckPermission("wms:instructions:edit")
    @Log(title = "来信须知", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MailboxInstructionsBo bo) {
        mailboxInstructionsService.updateByBo(bo);
        return R.ok();
    }

    /**
     * 删除来信须知
     *
     * @param ids 主键串
     */
    @SaCheckPermission("wms:instructions:remove")
    @Log(title = "来信须知", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        mailboxInstructionsService.deleteByIds(List.of(ids));
        return R.ok();
    }
}
